import 'package:flutter/material.dart';
import 'package:ost_flutter_module/class/entity/store/store_search_entity.dart';
import 'package:ost_flutter_module/class/store/course_detail_page/store_course_detail_page.dart';
import 'package:ost_flutter_module/class/store/course_page/widgets/store_course_grid_card.dart';
import 'package:ost_flutter_module/class/store/course_page/widgets/store_course_home_card.dart';
import 'package:ost_flutter_module/common/adapt.dart';
import 'package:ost_flutter_module/common/utils.dart';
import 'package:ost_flutter_module/widget/custom_widget/custome_section_header.dart';

class StoreSearchResultPage extends StatelessWidget {
  final StoreSearchEntity entity;

  const StoreSearchResultPage({Key key, this.entity}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    var shiftList = entity.shiftList ?? [];
    var goodsList = entity.goodsList ?? [];

    return CustomScrollView(
      slivers: [
        SliverList(
          delegate: SliverChildListDelegate(
            [
              Column(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  SizedBox(height: Adapt.px(Utils.padding)),
                  StoreSectionHeaderWidget(text: '相关课程'),
                  ListView.builder(
                    shrinkWrap: true,
                    physics: NeverScrollableScrollPhysics(),
                    itemCount: shiftList.length,
                    itemBuilder: (context, index) {
                      var shift = shiftList[index];
                      return StoreCourseHomeCard(
                        type: CourseCardType.values[0],
                        shift: shift,
                        onTap: (_) {
                          GMaterialPagePush.materialPagePush(context,
                              StoreCourseDetailPage(id: shift.productId));
                        },
                      );
                    },
                  ),
                ],
              ),
              goodsList.isNotEmpty
                  ? Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        SizedBox(height: Adapt.px(Utils.padding)),
                        StoreSectionHeaderWidget(text: '相关商品'),
                        GridView.builder(
                          shrinkWrap: true,
                          physics: NeverScrollableScrollPhysics(),
                          gridDelegate:
                              SliverGridDelegateWithFixedCrossAxisCount(
                            crossAxisCount: 2,
                            childAspectRatio: 17 / 19,
                          ),
                          itemCount: goodsList.length,
                          itemBuilder: (context, index) {
                            var goods = goodsList[index];
                            return StoreGridCard(goods: goods);
                          },
                        ),
                      ],
                    )
                  : Container(),
            ],
          ),
        ),
      ],
    );
  }
}
